package main

import (
	"fmt"
	"github.com/Andrew-M-C/go.jsonvalue"
)

func main(){
	fmt.Println("============")

	var  jsonStr string
	jsonStr="{\"Response\":{\"Result\":{\"//\":\"这里我假设需要查找下面这个字段：\",\"AnArray\":[{\"SomeString\":\"Hello,world!\"}]}}}"


	// 反序列化
	j, err := jsonvalue.UnmarshalString(jsonStr)
	if err != nil {
		fmt.Println("解析出错")
	}
	fmt.Println(j)
	// 获取我们要的字符串
	str, err := j.GetString("Response", "Result", "AnArray", 0, "SomeString")
	if err != nil {
		fmt.Println("=============出错了")
	}
	fmt.Printf("SomeString = '%s'\n", str)



	var  jsonStr2 string
	jsonStr2="{\"nodes\":[{\"order\":\"1\",\"attribute\":\"folder\",\"dir_name\":\"第1.1层文件名称\",\"book_file_id\":\"\",\"children\":[{\"order\":\"2\",\"attribute\":\"folder\",\"dir_name\":\"第1.2层文件名称\",\"book_file_id\":\"\",\"children\":[{\"order\":\"3\",\"attribute\":\"folder\",\"dir_name\":\"第1.2层文件名称\",\"book_file_id\":\"\",\"children\":[{\"order\":\"4\",\"attribute\":\"file\",\"dir_name\":\"\",\"book_file_id\":\"45454454545\",\"children\":null}]}]}]},{\"order\":\"5\",\"attribute\":\"file\",\"dir_name\":\"\",\"book_file_id\":\"4545sdsdgfs4454545\",\"children\":null}]}"
	// 反序列化
//	var data []byte = []byte(jsonStr2)
	j2, err2 := jsonvalue.UnmarshalString(jsonStr2)
	if err2 != nil {
		fmt.Println("解析出错")
	}
	fmt.Println(j2)

	str1, err1 := j2.Get("nodes",0,"dir_name")
	if err1 != nil {
		fmt.Println("=============出错了")
	}
	fmt.Println("=============str1 order=",str1)


}